home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Language / ExecTests / thiho.m < prev    next >
Text File  |  1990-08-31  |  1KB  |  59 lines

  1. %  Comments in Emerald go from '%' to end of line
  2. %  This little program creates two processes, which alternate printing
  3. %  hi and ho.  The monitor in 'innerObject' provides the mutual exclusion
  4. %  and synchronization.
  5.  
  6. const initialObject == object initialObject
  7.   const limit == 10
  8.   const newobj ==
  9.     object innerObject
  10.       export Hi, Ho
  11.       monitor
  12.     var printHiNext : Boolean <- true
  13.     const c : Condition == Condition.create
  14.     
  15.     operation Hi
  16.       if ! printHiNext then
  17.         wait c
  18.       end if
  19.       stdout.PutString["hi\^J"]
  20.       printHiNext <- false
  21.       signal c
  22.     end hi
  23.  
  24.     operation Ho
  25.       if printHiNext then
  26.         wait c
  27.       end if
  28.       stdout.PutString["ho\^J"]
  29.       printHiNext <- true
  30.       signal c
  31.     end ho
  32.       end monitor
  33.  
  34.       process
  35.     var i : Integer
  36.     i <- 0
  37.     loop
  38.       exit when i = limit
  39.       self.ho
  40.       i <- i + 1
  41.     end loop
  42.     stdout.PutString["Ho'er done.\^J"]
  43.     stdout.close
  44.       end process
  45.     end innerObject
  46.  
  47.   process
  48.     var i : Integer
  49.     stdin.close
  50.     i <- 0
  51.     loop
  52.       exit when i = limit
  53.       newobj.hi
  54.       i <- i + 1
  55.     end loop
  56.     stdout.PutString["Hi'er done.\^J"]
  57.   end process
  58. end initialObject
  59.